
namespace test
{
  type ApiResponse<T> = {
    code: number
    data: T
  };

  type UserResponse = ApiResponse<{
    id: string,
    name: string
  }>

  type EventResponse = ApiResponse<{
    id: string,
    title: string
  }>


  type ApiResponseEntity<T> = T extends ApiResponse<infer U> ? U : never;

  type User = ApiResponseEntity<UserResponse>; // { id: string; name: string; }
  type Event = ApiResponseEntity<EventResponse>; // { id: string; title: string; }


  // note: return type

  type A = (a: number) => string
  type B = ReturnType<A> // string

  // note: 获取方法参数
  type EventListenerParamsType = Parameters<typeof window.addEventListener>;

  //note: exclude
  type A = number | string
  type B = string
  type C = Exclude<A, B> // number

  //note: extract
  type A = number | string
  type B = string
  type C = Extract<A, B> // string

  //note: nonnull 从类型中排出null&undifine

  type A = {
    a?: number | null
  }
  type B = NonNullable(A['a']) // number
}
